﻿//==========================页面加载时JS函数开始===============================
//输入框显示提示效果，配合CSS运用
$(function() {
  $("input, .login_input, .textarea").focus(function() {
    $(this).addClass("focus");
  }).blur(function() {
    $(this).removeClass("focus");
  });
  //输入框提示,获取拥有HintTitle,HintInfo属性的对象
  $("[HintTitle], [HintInfo]").onmouseover(function(event) {
    $("*").stop(); //停止所有正在运行的动画
    $("#HintMsg").remove(); //先清除，防止重复出错
    var HintHtml = "<ul id=\"HintMsg\"><li class=\"HintTop\"></li><li class=\"HintInfo\"><b>" + $(this).attr("HintTitle") + "</b>" + $(this).attr("HintInfo") + "</li><li class=\"HintFooter\"></li></ul>"; //设置显示的内容
    var offset = $(this).offset(); //取得事件对象的位置
    $("body").append(HintHtml); //添加节点
    $("#HintMsg").fadeTo(0, 0.85); //对象的透明度
    var HintHeight = $("#HintMsg").height(); //取得容器高度
    $("#HintMsg").css({ "top": offset.top - HintHeight + "px", "left": offset.left + "px" }).fadeIn(500);
  }).blur(function(event) {
    $("#HintMsg").remove(); //删除UL
  });
});

//全选取消按钮函数，调用样式如：
function checkAll(chkobj) {
  if ($(chkobj).text() == "全选") {
    $(chkobj).text("取消");
    $(".checkall input").attr("checked", true);
  } else {
    $(chkobj).text("全选");
    $(".checkall input").attr("checked", false);
  }
}

//遮罩提示窗口
function jsmsg(w, h, msgtitle, msgbox, url, msgcss) {
  $("#msgdialog").remove();
  var cssname = "";
  switch (msgcss) {
  case "Success":
    cssname = "icon-01";
    break;
  case "Error":
    cssname = "icon-02";
    break;
  default:
    cssname = "icon-03";
    break;
  }
  var str = "<div id='msgdialog' title='" + msgtitle + "'><p class='" + cssname + "'>" + msgbox + "</p></div>";
  $("body").append(str);
  $("#msgdialog").dialog({
    //title: null,
    //show: null,
    bgiframe: true,
    autoOpen: false,
    width: w,
    //height: h,
    resizable: false,
    closeOnEscape: true,
    buttons: { "确定": function() { $(this).dialog("close"); } },
    modal: true
  });
  $("#msgdialog").dialog("open");
  if (url == "back") {
    sysMain.history.back(-1);
  } else if (url != "") {
    sysMain.location.href = url;
  }
}

//可以自动关闭的提示
function jsprint(msgtitle, url, msgcss) {
  $("#msgprint").remove();
  var cssname = "";
  switch (msgcss) {
  case "Success":
    cssname = "pcent correct";
    break;
  case "Error":
    cssname = "pcent disable";
    break;
  default:
    cssname = "pcent warning";
    break;
  }
  var str = "<div id=\"msgprint\" class=\"" + cssname + "\">" + msgtitle + "</div>";
  $("body").append(str);
  $("#msgprint").show();
  if (url == "back") {
    sysMain.history.back(-1);
  } else if (url != "") {
    sysMain.location.href = url;
  }
  //3秒后清除提示
  setTimeout(function() {
    $("#msgprint").fadeOut(500);
    //如果动画结束则删除节点
    if (!$("#msgprint").is(":animated")) {
      $("#msgprint").remove();
    }
  }, 3000);
};